const express = require('express');
const router = express.Router();
const service = require('../services/userService')
const infoService = require('../services/infoService')
const passport = require('passport')
const { body } = require('express-validator');
var multer = require('multer')
var upload = multer({ dest: './tmp/' })
const vaildatorLogin = [
  body('userid').isString().withMessage('用户名类型错误'),
  body('password').isString().withMessage('密码类型错误')
]
const vaildator = [
  body('userid').isString().withMessage('用户名类型错误'),
  body('password').isString().withMessage('密码类型错误'),
  body('nickname').isString().withMessage('密码类型错误'),
  body('avatar').isString(),
  body('phone').isString(),
  body('address').isString()
]
const dataForLoginWX = [
  body('code').isString().withMessage('code错误'),
  // body('password').isString().withMessage('密码类型错误')
]
const dataForUser = [
  body('userid').isString().withMessage('userid错误'),
  // body('password').isString().withMessage('密码类型错误')
]
const dataForShopInfo = [
  body('id').isString().withMessage('id错误')
]
const dataForShopOneInfo = [
  body('id').isString().withMessage('id错误')
]
const dataForAddressInfo = [
  body('userid').isString().withMessage('id错误'),
  body('name').isString().withMessage('name错误'),
  body('phone').isString().withMessage('phone错误'),
  body('province').isString().withMessage('province错误'),
  body('city').isString().withMessage('city错误'),
  body('county').isString().withMessage('county错误'),
  body('fulladdress').isString().withMessage('fulladdress错误'),
  body('defaultaddress').isString().withMessage('defaultaddress错误')
]
const dataForPlanInfo = [
  body('user_id').isString().withMessage('id错误'),
  body('plan').isString().withMessage('plan错误'),
  body('shop_id').isString().withMessage('shop_id错误'),
  body('address_id').isString().withMessage('address_id错误'),
]
const dataForPlanUserId = [
  body('shop_id').isString().withMessage('id错误')
]
const dataForApplyInfoId = [
  body('id').isString().withMessage('id错误')
]
const dataForApplyed = [
  body('id').isString().withMessage('user_id错误'),
  body('shop_id').isString().withMessage('shop_id')
]
const dataForArticleList = [
  body('cate').isString().withMessage('cate错误')
]
const dataForArticleDetail = [
  body('id').isString().withMessage('id错误')
]
const dataForSearchArticle = [
  body('content').isString().withMessage('content错误'),
]
const dataForArticleComment = [
  body('user_id').isString().withMessage('user_id'),
  body('article_id').isString().withMessage('article_id'),
  body('avatar').isString().withMessage('avatar'),
  body('user_name').isString().withMessage('user_name'),
  body('article_title').isString().withMessage('article_title'),
  body('comment_level').isString().withMessage('comment_level'),
  body('content').isString().withMessage('content'),
  body('status').isString().withMessage('status'),
  body('create_time').isString().withMessage('create_time')
]
const dataForArticleCommentReply = [
  body('user_id').isString().withMessage('user_id'),
  body('article_id').isString().withMessage('article_id'),
  body('avatar').isString().withMessage('avatar'),
  body('user_name').isString().withMessage('user_name'),
  body('article_title').isString().withMessage('article_title'),
  body('parent_comment_id').isString().withMessage('parent_comment_id'),
  body('parent_comment_user_id').isString().withMessage('parent_comment_user_id'),
  body('reply_comment_id').isString().withMessage('reply_comment_id'),
  body('reply_comment_user_id').isString().withMessage('reply_comment_user_id'),
  body('comment_level').isString().withMessage('comment_level'),
  body('content').isString().withMessage('content'),
  body('status').isString().withMessage('status'),
  body('create_time').isString().withMessage('create_time')
]
const dataForAddArticle = [
  body('user_id').isString().withMessage('user_id'),
  body('nickname').isString().withMessage('nickname'),
  body('avatar').isString().withMessage('avatar'),
  body('title').isString().withMessage('title'),
  body('picture').isString().withMessage('picture'),
  body('content').isString().withMessage('content'),
  body('cate').isString().withMessage('cate'),
  body('create_time').isString().withMessage('create_time'),
  body('update_time').isString().withMessage('update_time'),
  body('type').isString().withMessage('type'),
  body('isdelete').isString().withMessage('isdelete'),
  body('isrecommend').isString().withMessage('isrecommend'),
  body('hits').isString().withMessage('hits'),
  body('comment_sum').isString().withMessage('comment_sum'),
  body('publish_status').isString().withMessage('publish_status')
]
const dataForGetComment = [
  body('id').isString().withMessage('id错误'),
  body('comment_id').isString().withMessage('id错误')
]
const dataForAddFollow = [
  body('focus_user_id').isString(),
  body('focus_user_name').isString(),
  body('focus_user_avatar').isString(),
  body('user_id').isString(),
  body('user_name').isString(),
  body('user_avatar').isString(),
  body('create_time').isString()
]
const dataForGetFollowStatus = [
  body('focus_user_id').isString(),
  body('user_id').isString()
]
const dataForGetMyFollow = [
  body('user_id').isString()
]
const dataForGetMyFocus = [
  body('focus_user_id').isString()
]
const dataForSearchAdmin = [
  //nickname, type
  body('nickname').isString(),
  body('type').isString()
]
const dataForMyArticleList = [
  body('user_id').isString()
]
const dataForCancelFollow = [
  body('focus_user_id').isString(),
  body('user_id').isString()
]
const dataForGetMyShop = [
  body('user_id').isString()
]
const dataForaddCollection = [
  body('shop_id').isString(),
  body('user_id').isString()
]

const dataForgetMyCollection = [
  body('user_id').isString()
]
const dataForgetCollectionStatus = [
  body('user_id').isString(),
  body('shop_id').isString()
]
const dataFordeleteMyCollection = [
  body('user_id').isString(),
  body('shop_id').isString()
]
const dataForgetMyShopInfoList = [
  body('user_id').isString(),
  body('shop_id').isString()
]
const dataForgetMyAddressList = [
  body('user_id').isString()
]
const dataForgetAddressDetail = [
  body('id').isString()
]

const dataForupdateAddress = [
  body('address_id').isString(),
  body('name').isString(),
  body('phone').isString(),
  body('province').isString(),
  body('city').isString(),
  body('county').isString(),
  body('fulladdress').isString(),
  body('defaultaddress').isString(),
  body('user_id').isString()
]
const dataForupdateAdmin = [
  body('nickname').isString(),
  body('avatar').isString(),
  body('sign').isString(),
  body('userid').isString()
]
const dataForaddQuestion = [
  body('user_id').isString(),
  body('content').isString(),
  body('create_time').isString()
]
const dataForaddShop = [
  body('shop_name').isString(),
  body('sum').isString(),
  body('price').isString(),
  body('content').isString(),
  body('shop_cate_id').isString(),
  body('shop_cate_name').isString(),
  body('picture').isString(),
  body('create_time').isString(),
  body('limit_time').isString(),
  body('introduction').isString(),
  body('status').isString()
]
const dataForupdateShop = [
  body('shop_name').isString(),
  body('sum').isString(),
  body('price').isString(),
  body('picture').isString(),
  body('content').isString(),
  body('shop_cate_id').isString(),
  body('shop_cate_name').isString(),
  body('create_time').isString(),
  body('limit_time').isString(),
  body('shop_id').isString()
]
const dataFordeleteShop = [
  body('shop_id').isString()
]
const dataForupdateAdminForAdmin = [
  body('nickname').isString(),
  body('address').isString(),
  body('userid').isString(),
  body('avatar').isString(),
  body('phone').isString(),
]
const dataFordeleteAdmin = [
  body('userid').isString()
]
const dataForchangeArticleStatus = [
  body('id').isString()
]
const dataForupdateArticle = [
  body('title').isString(),
  body('content').isString(),
  body('cate').isString(),
  body('update_time').isString(),
  body('picture').isString(),
  body('id').isString()
]
const dataFordeleteArticle = [
  body('id').isString()
]
const dataForgetForm = [
  body('shop_id').isString()
]
const dataForgetUserList = [
  body('userList').isString()
]
const dataFordetermineChoose = [
body('formList').isString(),
body('chooseList').isString(),
body('shop_id').isString()
]
const dataForgetFormAddressList = [
body('shop_id').isString()
]
const dataForupdateAddressForm = [
body('formAddressList').isString()
]
const dataForgetReportList = [
body('shop_id').isString()
]
const dataForpassReport = [
  body('article_id').isString(),
  body('status').isString()
]
const dataForfinishForm = [
body('shop_id').isString()
]
const dataForchangeIndex = [
  body('idList').isString()
]
// console.log("vaildator", vaildator)
router.post('/register', vaildator, service.register)
router.post('/login', vaildatorLogin, service.login)
router.post('/loginWX', dataForLoginWX, service.loginWX)
router.post('/findUser', dataForUser, service.getUserIdInfo)
router.get('/getAllUser', infoService.getUserInfo)
router.post('/getAllShopCate', [], infoService.getAllShopCate)
router.post('/getShopList', dataForShopInfo, infoService.getShopList)
router.post('/getSwipterList', [], infoService.getSwipterList)
router.post('/getShopOne', dataForShopOneInfo, infoService.getShopOne)
router.post('/addAddressInfo', dataForAddressInfo, infoService.addAddressInfo)
router.post('/addPlan', dataForPlanInfo, infoService.addPlan)
router.post('/getAllPlanUser', dataForPlanUserId, infoService.getAllPlanUser)
router.post('/getAllapplyInfo', dataForApplyInfoId, infoService.getAllApplyInfo)
router.post('/isApplyed', dataForApplyed, infoService.isApplyed)
router.post('/getAllarticleCate', [], infoService.getAllarticleCate)
router.post('/getArticleList', dataForArticleList, infoService.getArticleList)
router.post('/getHotArticleList', [], infoService.getHotArticleList)
router.post('/getMyArticleList', dataForMyArticleList, infoService.getMyArticleList)
router.post('/getArticleDetail', dataForArticleDetail, infoService.getArticleDetail)
router.post('/searchArticle', dataForSearchArticle, infoService.searchArticle)
router.post('/addComment', dataForArticleComment, infoService.addComment)
router.post('/addReplyComment', dataForArticleCommentReply, infoService.addReplyComment)
router.post('/getComment', dataForGetComment, infoService.getComment)
router.all('/upload', upload.single('file'), infoService.uploadFile)
router.post('/addArticle', dataForAddArticle, infoService.addArticle)
router.post('/addFollow', dataForAddFollow, infoService.addFollow)
router.post('/getFollowStatus', dataForGetFollowStatus, infoService.getFollowStatus)
router.post('/getMyFollow', dataForGetMyFollow, infoService.getMyFollow)
router.post('/getMyFocus', dataForGetMyFocus, infoService.getMyFocus)
router.post('/searchAdmin', dataForSearchAdmin, infoService.searchAdmin)
router.post('/cancelFollow', dataForCancelFollow, infoService.cancelFollow)
router.post('/getMyShop', dataForGetMyShop, infoService.getMyShop)
router.post('/addCollection', dataForaddCollection, infoService.addCollection)
router.post('/getMyCollection', dataForgetMyCollection, infoService.getMyCollection)
router.post('/getCollectionStatus', dataForgetCollectionStatus, infoService.getCollectionStatus)
router.post('/deleteMyCollection', dataFordeleteMyCollection, infoService.deleteMyCollection)
router.post('/getMyShopInfoList', dataForgetMyShopInfoList, infoService.getMyShopInfoList)
router.post('/getMyAddressList', dataForgetMyAddressList, infoService.getMyAddressList)
router.post('/getAddressDetail', dataForgetAddressDetail, infoService.getAddressDetail)
router.post('/updateAddress', dataForupdateAddress, infoService.updateAddress)
router.post('/updateAdmin', dataForupdateAdmin, infoService.updateAdmin)
router.post('/addQuestion', dataForaddQuestion, infoService.addQuestion)

router.post('/addShop', dataForaddShop, infoService.addShop)

router.post('/updateShop', dataForupdateShop, infoService.updateShop)
router.post('/deleteShop', dataFordeleteShop, infoService.deleteShop)

router.get('/getAllAdmin', [], infoService.getAllAdmin)
router.post('/updateAdminForAdmin', dataForupdateAdminForAdmin, infoService.updateAdminForAdmin)
router.post('/deleteAdmin', dataFordeleteAdmin, infoService.deleteAdmin)
router.post('/changeArticleStatus', dataForchangeArticleStatus, infoService.changeArticleStatus)
router.post('/updateArticle', dataForupdateArticle, infoService.updateArticle)
router.post('/deleteArticle', dataFordeleteArticle, infoService.deleteArticle)
router.post('/getForm', dataForgetForm, infoService.getForm)
router.post('/getUserList', dataForgetUserList, infoService.getUserList)
router.post('/determineChoose', dataFordetermineChoose, infoService.determineChoose)
router.post('/getFormAddressList', dataForgetFormAddressList, infoService.getFormAddressList)
router.post('/updateAddressForm', dataForupdateAddressForm, infoService.updateAddressForm)
router.post('/getReportList', dataForgetReportList, infoService.getReportList)
router.post('/passReport', dataForpassReport, infoService.passReport)
router.post('/finishForm', dataForfinishForm, infoService.finishForm)
router.post('/changeIndex', dataForchangeIndex, infoService.changeIndex)
module.exports = router;